//
//  Spacing.swift
//  DesignKit
//
//  Created by Jake Lin on 24/10/20.
//

public extension CGFloat {
  
  static let twoExtraSmall: CGFloat = 4
  /// 8
  static let extraSmall: CGFloat = 8
  /// 12
  static let small: CGFloat = 12
  /// 16
  static let normal: CGFloat = 16
  /// 18
  static let medium: CGFloat = 18
  /// 24
  static let large: CGFloat = 24
  /// 32
  static let extraLarge: CGFloat = 32
  /// 40
  static let twoExtraLarge: CGFloat = 40
  /// 48
  static let threeExtraLarge: CGFloat = 48
}

public extension UIEdgeInsets {
  
  enum Edge {
    case top, leading, bottom, trailing, all, horizontal, vertical
  }

  static func padding(_ length: CGFloat = .extraSmall) -> UIEdgeInsets {
    return .padding(.all, length)
  }

  static func padding(_ horizontal: CGFloat, _ vertical: CGFloat) -> UIEdgeInsets {
    return .init(top: vertical, left: horizontal, bottom: vertical, right: horizontal)
  }

  static func padding(_ top: CGFloat, _ bottom: CGFloat, _ left: CGFloat, _ right: CGFloat) -> UIEdgeInsets {
    return .init(top: top, left: left, bottom: bottom, right: right)
  }

  static func padding(_ edge: Edge = .all, _ length: CGFloat = .extraSmall) -> UIEdgeInsets {
    switch edge {
    case .top:
      return .init(top: length, left: 0, bottom: 0, right: 0)
    case .bottom:
      return .init(top: 0, left: 0, bottom: length, right: 0)
    case .leading:
      return .init(top: 0, left: length, bottom: 0, right: 0)
    case .trailing:
      return .init(top: 0, left: 0, bottom: 0, right: length)
    case .horizontal:
      return .init(top: 0, left: length, bottom: 0, right: length)
    case .vertical:
      return .init(top: length, left: 0, bottom: length, right: 0)
    case .all:
      return .init(top: length, left: length, bottom: length, right: length)
    }
  }
}
